<template>
	<section>
		<el-row>
			<!--工具条1-->
			<!--如果有更多工具条,放开此注释
		<el-col :span="24" class="toolbar"  style="padding-bottom: 0px;">
			<el-col :span="4">
			</el-col>
		</el-col>
		-->

			<!--编辑界面 Position 广告位置-->
			<el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">

				<el-form-item label="位置名称" prop="name">
					<el-input v-model="editForm.name" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="宽度" prop="width">
					<el-input-number v-model="editForm.width" :min="0" :max="200"></el-input-number>
				</el-form-item>
				<el-form-item label="高度" prop="height">
					<el-input-number v-model="editForm.height" :min="0" :max="200"></el-input-number>
				</el-form-item>
				<el-form-item label="位置描述" prop="descs">
					<el-input v-model="editForm.descs" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="位置类型" prop="posType">
					<template slot-scope="scope">
						<el-select v-model="editForm.posType" placeholder="请选择位置类型" style="width: 60%;">
							<el-option v-for="item in posTypeOptions" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</template>
				</el-form-item>
				<el-form-item label="位置代码" prop="posCode">
					<el-input v-model="editForm.posCode" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="共享级别" prop="shareLvl">
          <template>
             <el-radio-group v-model="editForm.shareLvl">
               <el-radio :label="0">门店私有</el-radio>
               <el-radio :label="1">商户私有</el-radio>
               <el-radio :label="2">平台共有</el-radio>
             </el-radio-group>
          </template>
				</el-form-item>
				<el-form-item>
					<el-col :span="24">
						<el-col :span="4" :offset="16">
							<el-button @click.native="handleCancel">取消</el-button>
						</el-col>
						<el-col :span="4">
							<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
						</el-col>
					</el-col>
				</el-form-item>
			</el-form>
		</el-row>
	</section>
</template>

<script>
	import util from '@/common/js/util'; //全局公共库
	import {
		editPosition
	} from '@/api/mdp/arc/ad/position';

	export default {
		props: ['position', 'visible'],
		watch: {
			'position': function(position) {
				this.editForm = position;
			},
			'visible': function(visible) {
				if (visible == true) {
					//从新打开页面时某些数据需要重新加载，可以在这里添加
				}
			}
		},
		data() {
			return {
				posTypeOptions: [{
						value: '0',
						label: '总部店'
					},
					{
						value: '1',
						label: '具体门店'
					}
				],
				options: {}, //下拉选择框的所有静态数据
				editLoading: false,
				editFormRules: {
					id: [
						//{ required: true, message: '编号', trigger: 'blur' }
					]
				},
				//编辑界面数据  Position 广告位置
				editForm: {
					id: '',
					name: '',
					width: '',
					height: '',
					descs: '',
          locationId:'',
          shopId:'',
          posType:'',
          posCode:'',
          shareLvl:''
				}
				/**begin 在下面加自定义属性,记得补上面的一个逗号**/

				/**end 在上面加自定义属性**/
			} //end return
		}, //end data
		methods: {
			// 取消按钮点击 父组件监听@cancel="editFormVisible=false" 监听
			handleCancel: function() {
				this.$emit('cancel');
			},
			//编辑提交Position 广告位置父组件监听@submit="afterEditSubmit"
			editSubmit: function() {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							let params = Object.assign({}, this.editForm);
							editPosition(params).then((res) => {
								this.editLoading = false;
								var tips = res.data.tips;
								if (tips.isOk) {
									this.$refs['editForm'].resetFields();
									this.$emit('submit'); //  @submit="afterEditSubmit"
								}
								this.$message({
									message: tips.msg,
									type: tips.isOk ? 'success' : 'error'
								});
							}).catch(() => {
								this.editLoading = false;
							});
						});
					}
				});
			}
			/**begin 在下面加自定义方法,记得补上面的一个逗号**/

			/**end 在上面加自定义方法**/
		}, //end method
		components: {
			//在下面添加其它组件 'ad-position-edit':PositionEdit
		},
		mounted() {
			this.editForm = Object.assign(this.editForm, this.position);
			//加载下拉列表 如有需要去掉注释
			/**
			let optionsParams={code:'all',fieldNames:['sex']};
			selectCacheOptions(optionsParams).then(res=>{
				this.options=res.data.data;
			});
			**/
			//给下拉列表初始化默认值
			//this.editForm.xxx=getDefaultValue(this.options.xxx,'1');

			/**在下面写其它函数***/
		}
	}
</script>

<style scoped>

</style>
